/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vodjaho.jms;

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.annotation.Resource;
import javax.jms.ConnectionFactory;
import javax.jms.Topic;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import vodjaho.jms.controller.MessagesMediator;
import vodjaho.jms.ui.ConsumerFrame;
import vodjaho.jms.ui.ProducerFrame;

/**
 *
 * @author Maxim A. Kanev <ask.me.makes@gmail.com> [mkanev]
 */
public class Main {

    @Resource(mappedName = "vodjaho_jms")
    private static ConnectionFactory topicFactory;
    @Resource(mappedName = "vodjaho_topic")
    private static Topic topic;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                setupLAF();
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

                MessagesMediator mediator = new MessagesMediator(topicFactory, topic);

                final ProducerFrame producerFrame = mediator.getProducerFrame();
                Dimension frameSize = producerFrame.getSize();
                producerFrame.setLocation((screenSize.width - frameSize.width) / 2,
                        screenSize.height / 2 - frameSize.height);
                producerFrame.setVisible(true);

                final ConsumerFrame consumerFrame = mediator.getConsumerFrame();
                frameSize = consumerFrame.getSize();
                consumerFrame.setLocation((screenSize.width - frameSize.width) / 2,
                        screenSize.height / 2);
                consumerFrame.setVisible(true);
            }
        });
    }

    private static void setupLAF() {
        try {
            try {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            } catch (Throwable e) {
                System.out.println("Exception occured: " + e.toString());
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            }
        } catch (Exception e) {
            System.out.println("Exception occured: " + e.toString());
        }
    }

}
